Skip to content

euler.m #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 1, 2018
Merged

euler.m #158

merged 2 commits into from
Jul 1, 2018

Conversation

vasilisk075
Copy link
Contributor

Matlab implementation of the Forward_Euler method

Matlab implementation of the Forward_Euler method
@june128 june128 added the Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) label Jun 29, 2018
Copy link
Member

@jiegillet jiegillet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to the team @vasilisk075, thank you for submitting code :)

% Loop over time
while succes==0

t(i+1) = t(i) + dt; % Calculate next time
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dynamically growing vector sizes is bad practice, they should always be predefined. For t is is very easy to do since you already know the bounds and the time difference.

y(i+1) = y(i) + f( y(i) )*dt; % Update solution

% Calculate differce between 2 time steps
error=abs(( y(i+1) - y(i) )/dt);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't call this error, it's not an error, it's a slope. I also wouldn't use that as an indication that the computation is over. I would simply predefine the time vector, calculate the function for all time steps and plot that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your idea but ODEs usually reach a SteadyState, and this particular surely does, so why waste time computing something that practically stays the same?

Copy link
Member

@jiegillet jiegillet Jun 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if your function was actually a sinusoidal function? It would stop at the first extremum. In general you don't have prior knowledge of the function, and computational time is dirt cheap nowadays.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is dirt cheap, if you talk about small problems like that! Generally when i run a big simulation based on some differential equation, i need a creteria indicating that Steady State is reached and thus terminating the simulation. Normaly a don't know the amount of time steps needed for that.
But either way, i think that it is a long discussion, so i am going to update the code according to your suggestions.
Thank you!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, yeah, real world is more complex of course. Let's keep it simple here :)

@jiegillet
Copy link
Member

Also if you want your code to be included in the website, you should include the code in the chapter ,md file. Look at other PRs to see how to do that. Also we'll need to include matlab in the supported languages, book.json and .editorconfig files and all that. Maybe @Butt4cak3 can do that?

@Butt4cak3
Copy link
Contributor

I'll do the EditorConfig once this is merged.

@Butt4cak3
Copy link
Contributor

#166 adds Matlab to book.json. Let's just merge that one first and we don't have to deal with it here.

Implementation of Forward Euler method on Matlab
Copy link
Member

@jiegillet jiegillet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clean! Thank you for updating your code.

@jiegillet jiegillet merged commit 53185b2 into algorithm-archivists:master Jul 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants